package com.icangya.interceptor;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PaChongInterceptor  extends HandlerInterceptorAdapter {

        private Logger logger = Logger.getLogger(this.getClass());

        //@Autowired

        @Override
        public boolean preHandle(HttpServletRequest request,
                                 HttpServletResponse response, Object handler) throws Exception {
            /** 拦截到用户的请求了 */

            String ua = ((HttpServletRequest) request).getHeader("user-agenter").toLowerCase();

            if (ua.indexOf("micromessenger") > 0) {// 是微信浏览器
                return  true;
            }else{
                response.sendRedirect("https://baike.baidu.com/item/%E7%A5%9E%E7%BB%8F%E7%97%85");
                return false;
            }
        }

        @Override
        public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
                throws Exception {
        }

}
